package com.exigen.perflabstat.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import com.exigen.perflabstat.base.GenericJPADAO;
import com.exigen.perflabstat.dao.TestRawResultsDao;
import com.exigen.perflabstat.models.TestRawResults;


public class TestRawResultsJpaDao extends GenericJPADAO<TestRawResults, Long> implements TestRawResultsDao  {
	
	public TestRawResultsJpaDao() {
		super(TestRawResults.class);
	}

	@SuppressWarnings({ "unchecked", "unused" })
	public List<TestRawResults> allTestRawResults() {
		
		TestRawResults test = null;
		
		Query query = getEntityManager().createQuery("from TestRawResults");
		
		List<TestRawResults> result = query.getResultList();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public TestRawResults checkIfExists(TestRawResults t) {
		TestRawResults t1 = null;
		
		Query query = getEntityManager().createQuery("select t from TestRawResults t where t.TRANSACTION_ID = :transactionId and t.TRANSACTIONSTART = :transactionStart and t.VIRTUALUSER_NUMBER = :virtualUser");
		query.setParameter("transactionId", t.getTRANSACTION_ID());
		query.setParameter("transactionStart", t.getTRANSACTIONSTART());
		query.setParameter("virtualUser", t.getVIRTUALUSER_NUMBER());
		query.setMaxResults(1);
		
		List<TestRawResults> result = query.getResultList();
		
		if(result.isEmpty())return null;
		
		t1 = result.get(0);
		
		return t1;
	}

}
